{% extends 'users/base.html' %}
{% block title_block %} 登录 {% endblock %}
{% block body_block %}
    {% csrf_token %}
    <div class="form-signin">
        <h2 class="form-signin-heading text-center">请登录</h2>
        <label for="inputText">用户名</label>
        <input type="text" id="inputUsername" class="form-control" placeholder="用户名" required autofocus>
        <label for="inputPassword">密码</label>
        <input type="password" id="inputPassword" class="form-control" placeholder="密码" required>
        <label>还未注册？<a href="{% url 'users:register' %}">点击注册</a></label>
        <button id="login_btn" class="btn btn-lg btn-primary btn-block" type="submit">登录</button>
    </div>
<script>
$(function(){
    $('#login_btn').on('click', function(){
        var data = {
            'username': $('#inputUsername').val(),
            'password': $('#inputPassword').val(),
            'csrfmiddlewaretoken': $('input[name="csrfmiddlewaretoken"]').val()
        }
        $.post('/oa/login/', data, function(res){
            if(res.status == 1){
                window.location.href='{% url "users:index" %}';
            }else{
                $('#tip').html(res.msg)
            }
        }, 'json')
    }) 
})
</script>
{% endblock %}
